<?php
namespace app\common\logic\cast\news;



use app\common\logic\cast\Base;
use app\common\utils\Utils;


/**
 * Created by PhpStorm.
 * User: yangchunfu
 * Date: 2019/12/24
 * Time: 4:36 PM
 * 栏目
 */

class WxSuper extends Base
{
    protected $apiHref = 'http://api01.idataapi.cn:8000/post/weixinpro2';
    public function __construct($options= [], $tag = '')
    {
        $search = config('site.wxsearch');
        $key = array_rand($search,1);
        $value = $search[$key];
        $options = array_merge([
            'kw' => $value,
            'size' => 10,
        ], $options);

        parent::__construct($options, $tag);
    }

    /**
     * 获取插入字段
     * id,url,title,publishDate,imageUrls
     */
    public function getField($v) {
        $data['news_id'] = MD5($v['url']); //根据url生成 唯一id
        $data['url'] = $v['url'];
        $data['title'] = $v['title'];
        $data['publishDate'] = $v['publishDate'];
        if (isset($v['coverUrl'])) {
            $data['imageUrls'] = $v['coverUrl'];
        } else {
            $data['imageUrls'] = '';
        }

        return $data;
    }

    /**
     * 调用接口
     * @param mixed $options
     */
    public function get($options = []) {
        $switch1 = config('site.wx1switch');
        $switch2 = config('site.wx2switch');
        $res1 = [];
        $res2 = [];
        if ($switch1 == 1) {
            $res1 = parent::get();
        }

        if ($switch2 == 1) {
            //把bilibli视频放在西瓜目录下
            $res2 = (new Wx2Super([], 'wx_super'))->get();
        }

        $data = array_merge($res1, $res2);
        return $data;
    }

}